package com.example.cobodynamicproxydemo.service;

import com.example.cobodynamicproxydemo.data.UserDto;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserApiDemoClientImpl implements UserApiDemoClient {

    private static final List<UserDto> USERS = new ArrayList<>();

    static {
        for (int i = 0; i < 5; i++) {
            UserDto user = UserDto.builder()
                    .id(BigInteger.valueOf(i))
                    .username("user00" + i)
                    .password("pass00" + i)
                    .build();
            USERS.add(user);
        }
    }


    @Override
    public List<UserDto> list() {
        return USERS;
    }

    @Override
    public UserDto findById(BigInteger id) {
        return USERS.stream().filter(item -> item.getId().compareTo(id) == 0).toList().stream().findFirst().orElse(null);
    }
}
